Unit 4- PYQ

Q1. what is the Yule-Walker eqn and how are they used in the context of AR processes?

Great question! Let's break down the Yule-Walker Equations and how they are used in AR (AutoRegressive) processes in the simplest way possible.


🔁 What is an AR Process?

An AR(p) process is a type of time series model where:

Xt=ϕ1Xt−1+ϕ2Xt−2+⋯+ϕpXt−p+εtX_t = \phi_1 X_{t-1} + \phi_2 X_{t-2} + \dots + \phi_p X_{t-p} + \varepsilon_t


📐 What are Yule-Walker Equations?

Yule-Walker Equations help you calculate the AR coefficients (ϕ1,…,ϕp\phi_1, \dots, \phi_p) using autocorrelation values from your time series.

They are based on:

γ(k)=Cov(Xt,Xt−k)\gamma(k) = \text{Cov}(X_t, X_{t-k})

where γ(k)\gamma(k) is the autocovariance at lag kk.


🔧 Basic Form (for AR(1)):

For an AR(1) process:

Xt=ϕ1Xt−1+εtX_t = \phi_1 X_{t-1} + \varepsilon_t

The Yule-Walker equation becomes:

γ(1)=ϕ1γ(0)⇒ϕ1=γ(1)γ(0)=ρ(1)\gamma(1) = \phi_1 \gamma(0) \Rightarrow \phi_1 = \frac{\gamma(1)}{\gamma(0)} = \rho(1)

So the AR(1) coefficient is just the lag-1 autocorrelation!


🔢 General Form (for AR(p)):

You get a system of p equations:

γ(1)=ϕ1γ(0)+ϕ2γ(1)+⋯+ϕpγ(p−1)γ(2)=ϕ1γ(1)+ϕ2γ(0)+⋯+ϕpγ(p−2)⋮γ(p)=ϕ1γ(p−1)+⋯+ϕpγ(0)\gamma(1) = \phi_1 \gamma(0) + \phi_2 \gamma(1) + \dots + \phi_p \gamma(p-1) \ \gamma(2) = \phi_1 \gamma(1) + \phi_2 \gamma(0) + \dots + \phi_p \gamma(p-2) \ \vdots \ \gamma(p) = \phi_1 \gamma(p-1) + \dots + \phi_p \gamma(0)

You solve this system to find ϕ1,…,ϕp\phi_1, \dots, \phi_p.


💡 Why Are They Useful?


✅ Summary (Super Simple):


Would you like a numerical example too (like for AR(2))?

Q2. describe a scenario where deseasonlization would be crucial for accurate forecasting and analysis. How would you implement it?

Scenario Where Deseasonalization is Crucial:

Scenario:
A retail company sells air conditioners (ACs). Sales peak during summer (April to June) and drop in winter (December to February). You want to forecast future monthly sales to manage inventory and staff.

If you use raw sales data for forecasting, the model may:

🎯 Why Deseasonalization is Crucial:

To remove the seasonal effect, so you can:


⚙️ How to Implement Deseasonalization (Step-by-Step):

Let’s assume monthly data with seasonality of 12 months.


Step 1: Calculate Seasonal Indices

Use a multiplicative model:

Observed=Trend×Seasonal×Irregular\text{Observed} = \text{Trend} \times \text{Seasonal} \times \text

Or additive model:

Observed=Trend+Seasonal+Irregular\text{Observed} = \text{Trend} + \text{Seasonal} + \text

To get seasonal indices:

  1. Compute a centered moving average (e.g., 12-month for monthly data) to estimate trend.

  2. Subtract (additive) or divide (multiplicative) actual values by the trend to isolate seasonality.

  3. Average the seasonal values by month (Jan, Feb, ..., Dec).


Step 2: Deseasonalize the Data


Step 3: Model the Deseasonalized Series


Step 4: Reseasonalize the Forecast


📝 Example (Multiplicative):

Let’s say April sales = ₹1,20,000
April seasonal index = 1.5 (means sales are 50% higher than average due to summer)

Deseasonalized value = ₹1,20,000 ÷ 1.5 = ₹80,000
→ This ₹80,000 is the real performance without seasonal influence.


✅ Final Thoughts:

Deseasonalization is crucial when:

Q3.

Great! Deseasonalization using harmonic analysis is a powerful technique based on Fourier series—a method that models seasonality as a sum of sine and cosine waves.


🌊 What is Harmonic Analysis?

Harmonic analysis models seasonal patterns using sine and cosine functions, like:

S(t)=a0+∑k=1K(akcos⁡(2πktT)+bksin⁡(2πktT))S(t) = a_0 + \sum_{k=1}^{K} \left( a_k \cos\left(\frac{2\pi kt}{T}\right) + b_k \sin\left(\frac{2\pi kt}{T}\right) \right)

Where:


🧠 Goal:

Estimate the seasonal component S(t)S(t), then remove it from the original series to get the deseasonalized data.


✅ Steps for Deseasonalization Using Harmonic Analysis:


Step 1: Prepare the Time Series


Step 2: Choose the Period (T)


Step 3: Fit Harmonic Regression Model

Build a regression model of the form:

Y(t)=α+∑k=1K(akcos⁡(2πktT)+bksin⁡(2πktT))+Residual(t)Y(t) = \alpha + \sum_{k=1}^{K} \left( a_k \cos\left(\frac{2\pi kt}{T}\right) + b_k \sin\left(\frac{2\pi kt}{T}\right) \right) + \text{Residual}(t)


Step 4: Estimate Seasonal Component

Use the fitted coefficients to compute:

S^(t)=α^+∑k=1K(a^kcos⁡(2πktT)+b^ksin⁡(2πktT))\hat{S}(t) = \hat{\alpha} + \sum_{k=1}^{K} \left( \hat{a}_k \cos\left(\frac{2\pi kt}{T}\right) + \hat{b}_k \sin\left(\frac{2\pi kt}{T}\right) \right)

This gives you the estimated seasonal effect at each time point.


Step 5: Deseasonalize the Series

Subtract the seasonal component from the original data:

Deseasonalized(t)=Y(t)−S^(t)\text{Deseasonalized}(t) = Y(t) - \hat{S}(t)

Now you're left with the trend + irregular components (useful for forecasting).


Step 6 (Optional): Forecasting and Reseasonalizing


🧪 Example in One Line (Conceptual):

Imagine you're modeling monthly ice cream sales:

Fit a regression with terms like:
Sales ~ cos(2πt/12) + sin(2πt/12) + cos(4πt/12) + sin(4πt/12)
→ Use it to estimate seasonality → Subtract it → You get deseasonalized sales.


✅ Advantages of Harmonic Analysis:


Would you like me to show this in Python or Excel with sample data?